// 某个模块的数据请求（增删改查！）

import $axios from "@/common/http";  // 封装的axios
import axios from "axios"   // 原生的axios
import { Message } from "element-ui"  // 提示框

/**
 * 
 * @param {*} data  { uid:uid值 }  { size:每页数量  page:页码数 }
 */
export async function getAdmin(data) {
    let res;
    if (data.uid) {
        res = await $axios.get("/userinfo", { params: { uid:data.uid } });
    } else {
        res = await $axios.get("/userlist",{ params:data }); 
    }
    return res.list;
}

export async function getTotal(){
    let res = await $axios.get("/usercount");
    return res.list[0].total;
}

export async function addAdmin(data) {
    let res = await $axios.post("/useradd", data);
    Message.success(res.msg)
    return true;
}

export async function editAdmin(data) {
    let res = await $axios.post("/useredit", data);
    Message.success(res.msg)
    return true;
}

export async function delAdmin(uid) {
    if (!uid) {
        Message.warning("请传入删除uid");
        return;
    }
    let res = await $axios.post("/userdelete", { uid })
    Message.success(res.msg)
    return res.list;
}

/**
 * 登录
 * @param {*} data   用户信息  { username:"",password:"" }
 */
export async function login(data){
    let res = await $axios.post("/userlogin", data)
    Message.success('登录成功')
    return res.list;
}